<template>
    <div>
        <a-modal :title="title" :visible="visible" :confirm-loading="loading" @ok="handleOK" @cancel="handleCancel" cancelText="关闭" width="80%" >
            <a-table
                :columns="columns"
                :data-source="dataList"
                childrenColumnName='childrens'
                rowKey='timeNodeCode'
                :pagination="false"
                :indentSize='15'
                bordered
                :expandIcon="expandIcon"
                :defaultExpandAllRows='true'
                >
                <template slot="jobContent" slot-scope="text, record">
                    <a-textarea auto-size :value="record.jobContent" readOnly/>
                </template>
                <template slot="planStartDate" slot-scope="text, record">
                    <span>{{ record.planStartDate }}</span>
                </template>
                <template slot="completionDate" slot-scope="text, record">
                    <span>{{ record.completionDate }}</span>
                </template>
                <template slot="planStartDateAudit" slot-scope="text, record">
                    <span>{{ record.planStartDateAudit }}</span>
                </template>
                <template slot="completionDateAudit" slot-scope="text, record">
                    <span>{{ record.completionDateAudit }}</span>
                </template>
                <template slot="addReportUserName" slot-scope="text, record">
                    <span>{{record.addReportUserName}}</span>
                </template>
            </a-table>
            <template slot="footer">
                <a-button @click="handleCancel">关闭</a-button>
            </template>
        </a-modal>
    </div>
</template>

<script>
import Vue from 'vue'
import { getAction, getActionAsync, postAction } from '@/api/manage'
import { ACCESS_TOKEN, USER_NAME } from '@/store/mutation-types'
export default {
  components: {},
  computed: {
  },
  data() {
    return {
        dataList: [],
        freshKey: 0
    }
  },
  props:{
      visible: {
          Type: Boolean,
          default: false
      },
      loading: {
          Type: true,
          default: false
      },
      type: {
          Type: String,
          default: 'radio'
      },
      title: {
          Type: String,
          default: '请选择'
      },
      url: {
          Type: String,
          default: ''
      },
      columns: {
          Type: Array,
          default: []
      },
      projectBuildId: {
          Type: String,
          default: ''
      }
  },
  mounted() {
    this.handleSearch();
  },
  methods: {

      handleCancel(){
        this.$emit('cancleOk');
      },
       handleOK(){
          this.$emit('cancleOk');
      },
      handleSearch(){
          var vm=this;
          if (!this.projectBuildId) {
            return
          }
          getAction(this.url,{projectBuildId:this.projectBuildId}).then(res=>{
              vm.dataList=[];
              if(res.success){
                  var result=res.result;
                  vm.dataList=result;
              }else{
                  this.$message.warning(res.message)
              }
          }).catch(resp=>{
              this.$message.warning(resp.message)
          });
      },
      expandIcon(props){
        if (Array.isArray(props.record.childrens)&&props.record.childrens.length!=0) {
          // props.expanded=true;
          console.log(props.expanded,'expanded')
        if (props.expanded) {//有数据-展开时候图标
          return (
            <a
              style="color: 'black',margin-right:0px"
              onClick={(e) => {
                props.onExpand(props.record, e);
              }}
            >
              <a-icon type="minus-square" style="color:#5f5f5f;margin-right:5px"/>
            </a>
          );
        } else {//有数据-未展开时候图标
          return (
            <a
              style="color: 'black' ,margin-right:0px"
              onClick={(e) => {
                props.onExpand(props.record, e);
              }}
            >
              <a-icon type="plus-square" style="color:#5f5f5f;margin-right:5px"/>
            </a>
          );
        }
      } else {//无数据-图标
        return (
          <span></span>
        );
      }
    }
  }
}
</script>